//
//  HZWecomeVc.swift
//  weibo002
//
//  Created by 黑眼圈 on 16/4/19.
//  Copyright © 2016年 heiyan. All rights reserved.
//

import UIKit
import SDWebImage

class HZWecomeVc: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

      
        
        view.backgroundColor = UIColor.whiteColor()
        
        setupUI()
    }
    
    
    
    private func setupUI(){
        
        view.addSubview(icon)
     
        view.addSubview(nameLabel)
        
        
        //约束
        icon.snp_makeConstraints { (make) -> Void in
            
            make.size.equalTo(CGSize(width: 80, height: 80))
            make.centerX.equalTo(view.snp_centerX)
            make.top.equalTo(200)
        }
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            
            make.centerX.equalTo(icon.snp_centerX)
            make.top.equalTo(icon.snp_bottom).offset(10)
        }
        
        
    }
    
    
    // MARK: -  视图加载完成时
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        
        //约束动画
        
//        //更新约束
        icon.snp_updateConstraints { (make) -> Void in
            
            make.top.equalTo(100)
        }
        
        UIView.animateWithDuration(1, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            
            //开启约束动画
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                
                UIView.animateWithDuration(0.5, animations: { () -> Void in
                    
                    //显示名字
                    self.nameLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        
                        //发出通知跳转控制器
                        NSNotificationCenter.defaultCenter().postNotificationName(gotoName, object: self)
                        
                })
        }
        
        
    }
    

    
    //懒加载子控件
    lazy var icon:UIImageView = {
        
        let icon = UIImageView(image: UIImage(named: "avatar_default_big"))
        
        icon.layer.cornerRadius = 40
        icon.layer.masksToBounds = true
        

        let url = NSURL(string: (HZOAuthVM.sharedVM.model?.profile_image_url)!)
        
        icon.sd_setImageWithURL(url)

        return icon
    }()
    
    
    
    
    lazy var nameLabel:UILabel = {
        
        let nameLabel = UILabel()
        
        nameLabel.text = HZOAuthVM.sharedVM.model?.name
        nameLabel.textColor = UIColor.darkGrayColor()
        nameLabel.font = UIFont.systemFontOfSize(15)
        
        //让 label开始是完全透明的
        nameLabel.alpha = 0;
        
        return nameLabel
        
    }()
    
    
    
    
    
    
    
    
    

 }
